package by.grsu.coctails.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.RelativeLayout;
import by.grsu.coctails.R;
import by.grsu.coctails.constants.ApplicationConstants;
import by.grsu.coctails.model.Coctail;
import by.grsu.coctails.model.Ingredient;

public class FragmentCreator {

	public static void addIngredientFragment(FragmentActivity activity,
			Ingredient ingredient) {
		RelativeLayout layout = (RelativeLayout) activity
				.findViewById(R.id.pagerView);
		layout.setVisibility(View.VISIBLE);
		FragmentTransaction transaction = activity.getSupportFragmentManager()
				.beginTransaction();
		transaction.add(R.id.pagerView,
				IngredientFragment.newInstance(ingredient));
		transaction.addToBackStack(IngredientFragment.TAG);
		transaction.commit();

	}

	public static void addCompostionFragment(final FragmentActivity activity,
			Coctail coctail) {
		RelativeLayout layout = (RelativeLayout) activity
				.findViewById(R.id.pagerView);
		layout.setVisibility(View.VISIBLE);
		FragmentTransaction transaction = activity.getSupportFragmentManager()
				.beginTransaction();
		Fragment fragment = CompositionFragment.newInstance(coctail);
		transaction.add(R.id.pagerView, fragment);
		transaction.addToBackStack(CompositionFragment.TAG);
		transaction.commit();
	}

	public static void addNewCoctailFragment(final FragmentActivity activity) {
		RelativeLayout layout = (RelativeLayout) activity
				.findViewById(R.id.pagerView);
		layout.setVisibility(View.VISIBLE);
		FragmentTransaction transaction = activity.getSupportFragmentManager()
				.beginTransaction();
		Fragment fragment = new AddCoctailFragment();
		transaction.add(R.id.pagerView, fragment);
		transaction.addToBackStack(CompositionFragment.TAG);
		transaction.commit();
	}

	public static void addAllIngredientFragment(final FragmentActivity activity) {
		RelativeLayout layout = (RelativeLayout) activity
				.findViewById(R.id.pagerView);
		layout.setVisibility(View.VISIBLE);
		FragmentTransaction transaction = activity.getSupportFragmentManager()
				.beginTransaction();
		Fragment fragment = new ListIngredientFragment();
		Bundle bundle = new Bundle();
		bundle.putBoolean(
				ApplicationConstants.START_INGREDIENT_FRAGMENT_FOR_RESULT, true);
		fragment.setArguments(bundle);
		transaction.add(R.id.pagerView, fragment);
		transaction.addToBackStack(CompositionFragment.TAG);
		transaction.commit();
	}

}
